<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Overtrue\Wechat\Auth;


class UserController extends Controller
{

    protected $auth = null;

   /* public function __construct(){
    $this->auth = new Auth(env('WX_ID'),env('WX_SEC'));
      }*/
    public function __construct() {
       $this->auth = new Auth( env('WX_ID') ,env('WX_SEC') );
    }  
     /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    public function login(Request $request){
      // return '微信授权';
     $user = $this->auth->authorize($to = null, $scope = 'snsapi_userinfo', $state = 'STATE');
     $request->session()->put('user',$user->all());
       return back();
      }

    public function logout(Request $request){
       $request->session()->forget('user');
     }
}
